package aize.corp.freeconso;

import java.util.HashSet;
import java.util.Set;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

import database.DBAdapter;

import aize.corp.freeconso.R;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Guide extends Activity {
	
	
	private DBAdapter database = new DBAdapter(this);
	private AdView adView;
	
	@Override
	  public void onDestroy() {
	    adView.destroy();
	    super.onDestroy();
	  }
	
	@Override
    public void onPause() {
		super.onPause();
		finish();
	}
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.guide);
        
        adView = new AdView(this, AdSize.BANNER, "a14f43ef717b0a4");
        RelativeLayout layout = (RelativeLayout)findViewById(R.id.ad);
        layout.addView(adView);
        AdRequest AdRequest = new AdRequest();
        Set<String> keys = new HashSet<String>();
        keys.add("Free");
        keys.add("freebox");
        keys.add("adsl");
        keys.add("fai");
        keys.add("revolution");
        keys.add("mobile");
        keys.add("call");
        AdRequest.setKeywords(keys);
        adView.loadAd(AdRequest);
        
    	database.open();
    	if(database.countSetting() == 0) {
    		Toast.makeText(getApplicationContext(), "Merci de configurer vos identifiants !", Toast.LENGTH_SHORT).show();
    		database.close();
    		finish();  
    	}
    	else {
    		database.close();
    		TextView texteView = (TextView) findViewById(R.id.textViewTitle);
            Typeface font = Typeface.createFromAsset(getAssets(), "ariblk.ttf");
            texteView.setTypeface(font); 
    		
            UpdateDisplay();
    	}
    }

	private void UpdateDisplay() {
		((TextView) findViewById(R.id.name)).setText(getIntent().getStringExtra("aize.eu.freeconso.name"));
		((TextView) findViewById(R.id.tel)).setText(getIntent().getStringExtra("aize.eu.freeconso.tel"));
		((TextView) findViewById(R.id.date)).setText(getIntent().getStringExtra("aize.eu.freeconso.date"));
		
		((TextView) findViewById(R.id.conso_voix)).setText(getIntent().getStringExtra("aize.eu.freeconso.conso_voix"));
		((TextView) findViewById(R.id.conso_voix_h)).setText(getIntent().getStringExtra("aize.eu.freeconso.conso_voix_h"));
		((TextView) findViewById(R.id.conso_voix_num_spec)).setText(getIntent().getStringExtra("aize.eu.freeconso.conso_voix_num_spec"));
		
		((TextView) findViewById(R.id.conso_sms)).setText(getIntent().getStringExtra("aize.eu.freeconso.conso_sms"));
		((TextView) findViewById(R.id.conso_sms_h)).setText(getIntent().getStringExtra("aize.eu.freeconso.conso_sms_h"));
		
		((TextView) findViewById(R.id.conso_mms)).setText(getIntent().getStringExtra("aize.eu.freeconso.conso_mms"));
		((TextView) findViewById(R.id.conso_mms_h)).setText(getIntent().getStringExtra("aize.eu.freeconso.conso_mms_h"));
		
		((TextView) findViewById(R.id.conso_data)).setText(getIntent().getStringExtra("aize.eu.freeconso.conso_data"));
		((TextView) findViewById(R.id.conso_data_h)).setText(getIntent().getStringExtra("aize.eu.freeconso.conso_data_h"));
		
		((TextView) findViewById(R.id.total_forfait)).setText(getIntent().getStringExtra("aize.eu.freeconso.total_forfait"));
		((TextView) findViewById(R.id.total_forfait_h)).setText(getIntent().getStringExtra("aize.eu.freeconso.total_forfait_h"));
		((TextView) findViewById(R.id.total)).setText(getIntent().getStringExtra("aize.eu.freeconso.total"));
	}	
}